alien_0 = {'color': 'green', 'points': 5}
print(alien_0['color'])
print(alien_0['points'])

new_points = alien_0['points']
print(f"You just earned {new_points} points!")

alien_0['x_position'] = 0
alien_0['y_position'] = 25
print(alien_0)

alien_0 = {}
alien_0['color'] = 'green'
alien_0['points'] = 5
print(alien_0)

alien_0 = {'color': 'green'}
print(f"The alien is {alien_0['color']}.")

alien_0['color'] = 'yellow'
print(f"The alien is now {alien_0['color']}.")

alien_0 = {'x_position': 0, 'y_position': 25, 'speed': 'medium'}
print(f"Original position: {alien_0['x_position']}")
if alien_0['speed']=='slow':
    x_increment=1
elif alien_0['speed']=='medium':
    x_increment=2
else:
    x_increment = 3

alien_0['x_position']=alien_0['x_position']+x_increment
print(f"New position: {alien_0['x_position']}")

alien_0 = {'color': 'green', 'points': 5}
print(alien_0)
del alien_0['points']
print(alien_0)

favourite_language={
    'jane':'python',
    'amy':'c',
    "tom":"rust",
    "richal":'java'
}
language=favourite_language['richal'].title()
print(language)

#get()
alien_0 = {'color': 'green', 'speed': 'slow'}
point_value = alien_0.get('points', 'No point value assigned.')
print(point_value)

#练习6.work_1-6.3
ren={
    'name':"liu",
    'age':'25',
    'city':'dalian',
    'food':'huoguo'
}
print(ren['name'])
print(ren['food'])
print(ren)

favorite = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'rust',
    'phil': 'python',
    }
for i, j in favorite.items():
    print(f"{i.title()}'s favorite language is {j.title()}.")

friends=['jen','phil']
for i in favorite.keys():
    print(f'hi {i.title()}')
    if i in friends:
        language=favorite[i].title()
        print(f'{i.title()},i see you love{language}')
if 'erin'not in favorite.keys():
    print("Erin, please take our poll!")

print("The following languages have been mentioned:")
for language in favorite.values():
    print(language.title())

print("The following languages have been mentioned:")
for language in set(favorite.values()):
    print(language.title())

#practice6.6
favorite_languages = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'rust',
    'phil': 'python',
    }

people=['jen','liu','sarah','edward','phil','jane']

for i in people:
    if i in favorite_languages.keys():
        print(f'{i},thank you')
    else:
        print(f'{i},you are not on the list')

alien_0 = {'color': 'green', 'points': 5}
alien_1 = {'color': 'yellow', 'points': 10}
alien_2 = {'color': 'red', 'points': 15}
aliens = [alien_0, alien_1, alien_2]
for alien in aliens:
    print(alien)

aliens = []

for alien_number in range(30):
    new_alien = {'color': 'green', 'points': 5, 'speed': 'slow'}
    aliens.append(new_alien)

for alien in aliens[:3]:
    if alien['color'] == 'green':
        alien['color'] = 'yellow'
        alien['speed'] = 'medium'
        alien['points'] = 10

for alien in aliens[:5]:
    print(alien)
print('...')

print(f"Total number of aliens: {len(aliens)}")

pizza = {
    'crust': 'thick',
    'toppings': ['mushrooms', 'extra cheese']
    }
print(f"You ordered a {pizza['crust']}-crust pizza "
      "with the following toppings:")

for topping in pizza['toppings']:
    print(f"\t{topping}")


favorite_languages = {
      'jen': ['python', 'rust'],
      'sarah': ['c'],
      'edward': ['rust', 'go'],
      'phil': ['python', 'haskell'],
      }

for i,j in favorite_languages.items():
    print(f"{i}'s favorite language is:")
    for a in j:
        print(f'{a.title()}')

#practice 6.7-6.12
pet_1={
    'master':'liu',
    'variety':'dog',
    'name':'cake',
    'age':1
}

pet_2={
    'master':'wang',
    'variety':'cat',
    'name':'pizza',
    'age':3
}
pet_3={
    'master':'liu',
    'variety':'hamster',
    'name':'apple',
    'age':0.7
}
pets=[pet_1,pet_2,pet_3]
print(pets)
for i in pets:
    print(i)


cities={
    'dalian':{
        'country':'china',
        'population':200000000,
        'fact':"near by sea"
    },
    'xian':{
        'country':'china',
        'population':100000000,
        'fact':"yangroupaomo"
    },
    'tokyo':{
        'country':'japan',
        'population':300000000,
        'fact':"guotuhenxiao"
    }

}
for i,j in cities.items():
    print('城市:',i)
    for m,n in j.items():
        print('\t',m,':',n)